package com.yihaodian.index.meta.shard;

public class ShardId {

	private String _indexId;
	private String _shardId;

	private ShardId() {

	}

	public ShardId(String indexId, String shardId) {
		this._indexId = indexId;
		this._shardId = shardId;
	}

	public String getIndexId() {
		return _indexId;
	}

	public String getShardId() {
		return _shardId;
	}

	/**
	 * In a single index (RoutingTable/IndexMeta), use shardId. In global, use
	 * UUID.
	 * 
	 * @return
	 */
	public String getUUId() {
		return _indexId + "-" + _shardId;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((_indexId == null) ? 0 : _indexId.hashCode());
		result = prime * result
				+ ((_shardId == null) ? 0 : _shardId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ShardId other = (ShardId) obj;
		if (_indexId == null) {
			if (other._indexId != null)
				return false;
		} else if (!_indexId.equals(other._indexId))
			return false;
		if (_shardId == null) {
			if (other._shardId != null)
				return false;
		} else if (!_shardId.equals(other._shardId))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return _indexId + "_" + _shardId;
	}
}
